
#表结构说明文件
class Record():
    key = ''
    type = ''
    comment = ''
    foreign = None

    def __init__(self, key, type, comment=None, foreign=None, increase=None, primary=False):
        self.key = key
        self.type = type
        self.foreign = foreign
        self.comment = comment
        self.increase = increase
        self.primary = primary


class BaseTableStructure():
    """
    基础表结构
    """
    id = Record('id', 'VARCHAR(100)', 'identification')
    create_date = Record('create_time', 'DATETIME', 'date of create')
    create_time = create_date

    TableName = ''

    def all_key(self) -> list:
        """
        列出所有属性
        :return:属性名称列表
        """
        import re
        dir = self.__dir__()
        res = []
        keys = []
        records = []

        for par in dir:
            if not re.match("__.*__", par):
                res.append(par)

        for key in res:
            if hasattr(self, key):  # 检查实例是否有这个属性
                rec = getattr(self, key)  # same as: print a.name
                if isinstance(rec, Record):
                    # val = getattr(per, 'key')
                    keys.append(rec.key)
                    records.append(rec)
                    # print(rec.key)

        return records
        # return ','.join(keys)
        # print(dir)